﻿Public Class FormOper2
    Private WithEvents UcDigitalKeyboard1 As ucDigitalKeyboard
    Public usr As String
    Public ty As String
    Public current_procedure_No As Integer
    Public current_procedure_Name As String
    Dim dt As DataTable
    Dim objGtProcedureOperatedDetails As New clsGtProcedureOperatedDetails
    Private Sub FormOper2_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Me.Text = current_procedure_Name & Me.Text
        setData()
    End Sub

    Public Sub setData()
        dt = objGtProcedureOperatedDetails.getGtProcedureOperatedDetials(ty, "'1'", (current_procedure_No - 1).ToString(), 0)
        dt.Columns.Add("oper_type_name")
        If dt.Rows.Count > 0 Then
            For Each row As DataRow In dt.Rows
                If row("oper_type") = "0" Then
                    row("oper_type_name") = "骨架板"
                Else
                    row("oper_type_name") = "法兰板"
                End If
            Next
        End If
        If dt.Rows.Count > 0 Then
            txt_ID.Text = dt.Rows(0)("sys_id")
            lblGroupNo.Text = dt.Rows(0)("group_no")
            lblgt.Text = dt.Rows(0)("b_gt_sys_id")
            lblgtProcedure.Text = dt.Rows(0)("b_gt_procedure_sys_id")
            lblgtProcedureOperated.Text = dt.Rows(0)("b_gt_procedure_operated_sys_id")
            txt_oper_type_name.Text = dt.Rows(0)("oper_type_name")
            txt_type_value.Text = dt.Rows(0)("type_value")
            txt_batch_no.Text = dt.Rows(0)("batch_no")
            txt_operable_num.Value = Integer.Parse(dt.Rows(0)("ok_num"))
        End If
    End Sub

    Private Sub txt_num_MouseDown(sender As Object, e As MouseEventArgs) Handles txt_num.MouseDown
        UcDigitalKeyboard1 = New ucDigitalKeyboard
        If sender.MaskBox.Mask.EditMask = "d" Then
            UcDigitalKeyboard1.B_01 = False
        Else
            UcDigitalKeyboard1.B_01 = True
        End If

        If sender.GetType().Name.Equals("TextEdit") Then
            UcDigitalKeyboard1.B_02 = True
        Else
            UcDigitalKeyboard1.B_02 = False
        End If

        UcDigitalKeyboard1.Txt = sender

        Me.Controls.Add(UcDigitalKeyboard1)
        UcDigitalKeyboard1.Show()
        UcDigitalKeyboard1.BringToFront()
        UcDigitalKeyboard1.Focus()
    End Sub

    Private Sub btnSave_Click(sender As Object, e As EventArgs) Handles btnSave.Click
        If Integer.Parse(txt_num.Value) > 0 Then
            If Integer.Parse(txt_num.Value) <= Integer.Parse(txt_operable_num.Value) Then
                Dim en As New entity_gt_procedure_operated_details
                en.procedure_No = current_procedure_No
                en.oper_num = Integer.Parse(txt_operable_num.Value)
                en.ok_num = Integer.Parse(txt_num.Value)
                en.oper = usr
                en.group_no = lblGroupNo.Text
                en.sys_id = Integer.Parse(txt_ID.Text)
                en.b_gt_procedure_operated_sys_id = Integer.Parse(lblgtProcedureOperated.Text)
                en.b_gt_procedure_sys_id = Integer.Parse(lblgtProcedure.Text)
                en.b_gt_sys_id = Integer.Parse(lblgt.Text)
                Dim rtn As Integer = objGtProcedureOperatedDetails.save2(ty, en)
                If rtn <> -2 Then
                    MsgBox("入料成功")
                    Close()
                Else
                    MsgBox("入料失败")
                End If
            Else
                MsgBox("入料数量＞可入料数量！")
            End If
        Else
            MsgBox("入料数量需>0")
        End If
    End Sub
End Class